<template>
	<view class="login_res_view">
		<view class="c_login_sy">
			<view class="c_title">
				授权登录
			</view>
			<view class="c_sm">
				申请获取一下权限：
			</view>
			<view class="c_tc">
				获取你的公开信息（昵称、头像、地区等）
			</view>
			<button class="pub_s_btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"
				style="width: 100%;" v-if="isRadio">
				<text style="width: 100%;">手机号快捷登录</text>
			</button>
			<button class="pub_s_btn" @click="shouquan" style="width: 100%;" v-if="!isRadio">
				<text style="width: 100%;">手机号快捷登录</text>
			</button>
			<button class="pub_s_btn dul" style="width: 100%;" @click="$emit('closePop')">
				<text style="width: 100%;">拒绝</text>
			</button>
			<label class="c_radio" style="margin-right: 30rpx;" @click="isRadio = !isRadio">
				<radio value="r1" color="#3568DB" :checked="isRadio" style="transform: scale(.7);" />请阅读并同意<span class="a_link" @click.stop="toyinsi">《志愿填报小程序隐私保护指引》</span>
			</label>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showYinsi:false,
				yamTime:0,
				yTimer:"",
				phone:"",
				code:"",
				tid:"",
				PhoneCode:"",
				isPhone:false,
				isRadio:false
			}
		},
		beforeDestroy() {
			let this_ = this;
			try{
				clearInterval(this_.yTimer);
				this.yTimer = "";
			}catch(e){
				//TODO handle the exception
			}
		},
		onLoad(ph) {
			if(ph.tid){
				this.tid = ph.tid
			}
		},
		methods: {
			shouquan(){
				let this_ = this;
				uni.showModal({
					title: '提示',
					confirmText:"同意",
					cancelText:"不同意",
					content: '请阅读并同意《志愿填报小程序隐私保护指引》内容',
					success: function (res) {
						if (res.confirm) {
							console.log('用户点击确定');
							this_.isRadio = true;
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			toyinsi(){
				uni.navigateTo({
					url:"/pages/detail/webView?url=yinsi"
				})
			},
			wechatLogin(){
				let shareId = uni.getStorageSync('shareId') || "";
				let shareInfo = {};
				if(shareId){
					shareInfo = {
						spm:shareId+".1.0.3.1",
						shareId:shareId,
						platform:"WechatMiniProgram",
						page:"/pages/index/index"
					}
				}
				uni.login({
				  provider: 'weixin',
				  success: (loginRes)=> {
					let js_code=loginRes.code;
						this.$queryApi("post","/third.wechat/getSessionId", {
							platform:'miniProgram',
							shareInfo,
							'payload':encodeURIComponent(
							  JSON.stringify({
								code: js_code,
								auto_login:false,
							  }),
							)
						}, SessionId => {
							console.log(SessionId,"getSessionId")
							uni.setStorageSync('sessionId',SessionId.data.session_id)
							this.$queryApi("post","/third.wechat/login", {
								platform:'miniProgram',
								shareInfo,
								'payload':encodeURIComponent(
									JSON.stringify({
									  sessionId: SessionId.data.session_id,
									}),
								  )
								}, res => {
								console.log(res,"login")
								uni.setStorageSync('token',res.data.token)
								if(shareId){
									//挂接分享上级
									this.$queryApi("post","/share/add", shareInfo, res => {},"","noMsg")
								}
								//获取用户信息
								this.$queryApi("post","/user.user/profile", {}, res => {
									console.log(res,"login")
									this.$store.commit("login",res.data)
									this.$emit("closePop")
								},"","noMsg")
							},"false","noMsg")
						},"false","noMsg")
					},
				})
			},
			getPhoneNumber(e) {
				if(!this.isRadio){
					this.$msg("请阅读并同意隐私保护")
				}else{
					this.PhoneCode = e.detail.code
					console.log(e.detail.code)
					this.isPhone = true;
					this.wechatLogin();
				}
				
			},
			yanzhangPhone(){
				
				
				let dataL = {
					mobile:this.phone,
					code:this.code
				}
				this.$queryApi("post","user.user/changeMobile", dataL, res => {
					console.log(res)
					uni.navigateTo({
						url:"/pages/login/loginRes2?phone="+this.phone+"&code="+this.code+"&tid="+this.tid
					})
				},"false")
				uni.navigateTo({
					url:"/pages/login/loginRes2?phone="+this.phone+"&code="+this.code+"&tid="+this.tid
				})
				
			},
			nativeTo(url){
				uni.navigateTo({
					url:url
				})
			},
			getYzm(){
				let this_ = this;
				this.yamTime = 30;
				let dataL = {
					phone:this.phone,
					event:"changemobile"
				}
				this.yTimer = setInterval(()=>{
					if(this.yamTime > 0){
						--this.yamTime;
						if(this.yamTime == 0){
							clearInterval(this_.yTimer);
							this.yTimer = "";
						}
					}
				},1000)
				// 1绑定2修改手机号3忘记密码4直接登录5修改密码
				this_.$queryApi("post","index/send", dataL, res => {
					
					
				},"")
			}
		}
	}
</script>

<style lang="scss">
	

	.login_res_view{
		padding: 34rpx 30rpx 100rpx;
		background-color: #fff;
		border-radius: 30rpx 30rpx 0 0;
		.c_login_sy{
			text-align: center;
			.c_title{
				font-size: 36rpx;
				color: #333;
				padding-bottom: 40rpx;
			}
			.c_sm{
				color: #999999;
				font-size: 28rpx;
				
			}
			.c_tc{
				font-size: 32rpx;
				padding: 20rpx 0 40rpx;
			}
			.pub_s_btn{
				width: 638rpx;
				height: 80rpx;
				border-radius: 60rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				background: linear-gradient( 270deg, #3568DB 0%, #3676F4 100%);
				margin-bottom: 20rpx;
				&.dul{
					background: #D1D5E0;
					// margin: 60rpx 20rpx 40rpx;
				}
			}
			.c_radio{
				font-size: 24rpx;
				padding-top: 40rpx;
				display: inline-block;
				.a_link{
					color: #3677F6;
				}
			}
		}

	}
</style>
